package cn.jason.service.impl;//package cn.jason.service.impl;
//
//import cn.jason.domain.Goods;
//import cn.jason.mapper.GoodsMapper;
//import cn.jason.service.IGoodsService;
//import cn.jason.utils.DbGoodsLock;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.Map;
//
//@Service
//public class GoodsServiceImpl_db_key implements IGoodsService {
//
//    @Autowired
//    private GoodsMapper goodsMapper;
//
//    @Transactional
//    @Override
//    public void updateNum(Map<String,Object> params) {
//        Long goodsId = (Long) params.get("id");
//        Integer num = (Integer) params.get("num");
//        System.out.println(Thread.currentThread().getName()+"enter！");
//        DbGoodsLock lock = new DbGoodsLock(goodsId);
//        try{
//
//            lock.lock();
//            System.out.println(Thread.currentThread().getName()+"获取锁成功===================");
//            Goods goods = goodsMapper.laodById(goodsId);
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            if (goods.getCount()>=num){
//                goodsMapper.updateNum(params);
//                System.out.println(Thread.currentThread().getName()+"修改num成功===================");
//            }
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }finally {
//            if (lock != null) {
//                lock.unlock();
//                System.out.println(Thread.currentThread().getName()+"释放锁成功===================");
//            }
//        }
//
//
//    }
//
//    @Override
//    public Goods getById(Long id) {
//        return goodsMapper.laodById(1L);
//    }
//}
